package cn.bdqn.service.impl;

import cn.bdqn.domain.Druginfo;
import cn.bdqn.domain.Drugsware;
import cn.bdqn.domain.Recipe;
import cn.bdqn.mapper.DruginfoMapper;
import cn.bdqn.mapper.RecipeMapper;
import cn.bdqn.service.DrugInfoService;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DrugInfoServiceImpl implements DrugInfoService {

    @Autowired
    private DruginfoMapper druginfoMapper;

    @Autowired
    private RecipeMapper recipeMapper;

    @Autowired
    private AmqpTemplate amqpTemplate;

    /**
     * 查询所有药品信息
     * @return
     */
    @Override
    public List<Druginfo> queryAll() {
        return druginfoMapper.selectByAll();
    }

    /**
     * 根据药品类型查询药品信息
     * @param type
     * @return
     */
    @Override
    public List<Druginfo> queryByType(String type) {
        return druginfoMapper.selectByDrugType(type);
    }

    /**
     * 根据药品名查询药品信息 模糊查询
     * @param name
     * @return
     */
    @Override
    public List<Druginfo> queryByNameLike(String name) {
        return druginfoMapper.selectAllByDrugNameLike(name);
    }

    /**
     *
     * @param recipe
     * @return
     */
    @Override
    public int addRecipe(Recipe recipe) {


        String msg = "处方添加通知";
        amqpTemplate.convertAndSend("","DOCTOR-Queue",msg);
        return recipeMapper.insertSelective(recipe);
    }

}
